#!/usr/bin/php
<?php
/***************************************************************************
 *
 *   copyright            : (C) 2005 Winds of Storm
 *
 *   $Id: timers.php,v 1.6 2005/12/13 20:07:45 nathan Exp $
 *
 ***************************************************************************/

/***************************************************************************
 *
 *   This program is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation; either version 2 of the License, or
 *   (at your option) any later version.
 *
 ***************************************************************************/

require(dirname(__FILE__) . "/../config.php");
$skip_header = 1;
require($libdir . "init." . $phpEx);
require($libdir . "chat_functs." . $phpEx);


$sql    = "SELECT * FROM ${dbprefix}alarms WHERE alarm_time < NOW() AND alarm_inactive=0";
if ($result = $db->sql_query($sql)) {
    while ($row = $db->sql_fetchrow($result)) {
        $sql    = "INSERT INTO ${dbprefix}events (user_id_from, room_id_to, user_id_to, event_text, event_date, event_chat_flags) VALUES (${row['alarm_user_id']}, ${row['alarm_room_to']}, ${row['alarm_user_to']}, '${row['alarm_text']}', NOW(), ${row['alarm_type']})";
        $db->sql_query($sql);
        $sql    = "UPDATE ${dbprefix}alarms SET alarm_inactive=1 WHERE alarm_id=${row['alarm_id']}";
        print $sql."\n";
        $db->sql_query($sql);
    }
}

